package com.wing.order.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.PageResult;
import com.wing.order.model.entity.InventoryInoutJob;
import com.wing.order.model.response.InventoryAlarmDetailVO;
import com.wing.order.model.response.InventoryInoutJobVO;
import com.wing.order.service.InventoryInoutJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Validated
@Api(value = "Admin-出/入库作业单记录管理", tags = "出/入库作业单记录管理")
@RestController("appInventoryInoutJobController")
@RequestMapping("order/app/inventoryInoutJob")
@RequiredArgsConstructor
public class InventoryInoutJobController {

    private final InventoryInoutJobService inventoryInoutJobService;

    @ApiOperation(value = "查询所有出库作业(领货)单记录", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "第几页", defaultValue = "1", example = "1", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "limit", value = "每页多少条", defaultValue = "10", example = "10", dataType = "Integer", paramType = "query")
            ,@ApiImplicitParam(name = "sort", value="排序字段名", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
            ,@ApiImplicitParam(name = "order", value="排序规则(asc:正序, desc:倒序)", defaultValue = "asc", example = "asc", dataType = "String", paramType = "query")
    })
    @GetMapping("/list4loading")
    public PageResult<InventoryInoutJobVO> list4loading(
            @RequestParam(defaultValue = "1") Integer page
            ,@RequestParam(defaultValue = "10") Integer limit
            ,@RequestParam(defaultValue = "create_time") String sort
            ,@RequestParam(defaultValue = "asc") String order
    ){
        Page<InventoryAlarmDetailVO> pg = new Page<>(page, limit);
        Map<String, Object> params = new HashMap<>();

        //排序
        if (StringUtils.isNotBlank(sort) && StringUtils.isNotBlank(order)) {
            params.put("sort", sort);
            params.put("order", order);
        }
        params.put("fromSign",InventoryInoutJob.FromSign.app.getValue());
        //搜索
        IPage<InventoryInoutJobVO> list = inventoryInoutJobService.pageList4loading(pg,params);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

}
